<?php
session_start();
if(!isset($_SESSION['login']) || $_SESSION['id_droit'] != 1) header('location:../vue/index.php');
    ?>
    <!DOCTYPE html>
    <!--
    To change this license header, choose License Headers in Project Properties.
    To change this template file, choose Tools | Templates
    and open the template in the editor
    -->
    <html>
        <head>
            <meta charset="UTF-8">
            <title></title>
			<style type="text/css">
		body{
                min-width:800px;
                width:auto!important;
                width:800px;
                height:5000px;
                background-image:url(../img/sharp_edge.png);
                background-repeat:repeat;
				<!--background-attachment:fixed;-->
            }
			
		td{
			color:white;
		}
		
		th{
			color:white;
		}
		
		td select{
			color:black;
		}
		
		td input{
			color:black;
		}
		
		
		</style>
        </head>
		
		<script type="text/javascript">

        function supprimerUtilisateur(uti_id) {
            document.location.href = "../controleur/supp_utilisateur.php?uti_id=" + uti_id;
        }
		
		function hide_conf(conf_id) {

            if (document.getElementById(conf_id).style.visibility == "hidden")
                document.getElementById(conf_id).style.visibility = "visible";
            else
                document.getElementById(conf_id).style.visibility = "hidden";
            return true;

        }
		</script
        <body>
            <?php
			include 'Include.php';
            include 'navBar.php';
            include_once '../model/model_sql.php';
            $modelSQL = new SQLBlog();
            $listeUser = $modelSQL->AfficherUtilisateurs();
            echo "<form method='POST' action='../controleur/modif_droit.php' style=\"margin:0 5% 0 5%;\">
            <table class='table'>
            <th>login</th><th>Nom</th><th>Prenom</th><th>date de naissance</th><th>date inscription</th><th>droit</th><th>Supprimer?</th>
            ";
            $i = 0;
			if($listeUser)
			{
				foreach ($listeUser as $var) {

					echo "
				<tr>
					<td>" . $var['login'] . "</td>
				<td>" . $var['nom'] . "</td>
				<td>" . $var['prenom'] . "</td>
				<td>" . $var['dateDeNaissance'] . "</td>
				<td>" . $var['dateInscription'] . "</td>
				<td><select name='select" . $i . "' ". ($var['id'] == 1 &&  $var['id_droit'] == 1? "disabled":"") .">
				<option value= '1' style=\"color:black;\"";
					if ($var['id_droit'] == 1) {
						echo "selected ";
					}
					echo ">Administrateur</option><option value='2'";
					if ($var['id_droit'] == 2) {
						echo "selected ";
					}
					echo ">Contributeur</option><option value='3'";
					if ($var['id_droit'] == 3) {
						echo "selected ";
					}
					echo ">Visiteur</option></select>"
					. "<input type='hidden' name='idUser" . $i . "' value='" . $var['id']
					. "'></td>"
				."<td><button style=\"margin:0 0 10px 10px;\" type=\"button\" name=\"modif\" class=\"btn btn-sm btn-danger\" onclick=\"hide_conf('conf_" . $var['id'] . "')\" ".($var['id_droit'] == 1  ? "disabled":"")."><span class=\"glyphicon glyphicon-trash\"></span></button>
				<button style=\"margin:0 0 10px 10px;visibility:hidden;\" type=\"button\" name=\"confirm\" class=\"btn btn-sm btn-warning\" id=\"conf_" . $var['id'] . "\" onclick=\"supprimerUtilisateur(" . $var['id'] . ")\">Confirmer</button></td>"
				."</tr>";
					$i++;
				
				;
				}
				echo "<tr><td colspan='7'><br/><input type='submit' class=\"btn btn-sm btn-success\"></td></tr></table></form>";
			}
			else
			{
				echo "<tr><td colspan='7'><br/><p>Aucun utilisateurs</p></td></tr></table></form>";
			}
            ?>
        </body>
    </html>